﻿using System;
using YXShop.Common.TaoBaoAPI;


namespace YXShop.Common.TaoBaoAPI
{
    ///参考top4net SDK
    /// <summary>
    /// TOP基于REST的XML客户端帮助类。
    /// </summary>
    public class TopXmlRestClient
    {
        private ITopClient client;

        public TopXmlRestClient(string topUrl, string appKey, string appSecret)
        {
            client = new TopRestClient(topUrl, appKey, appSecret, TopRestClient.FORMAT_XML);
        }

        /// <summary>
        /// 获取请求
        /// </summary>
        public string GetResponse(ITopRequest request)
        {
            return client.Execute(request, new StringParser());
        }

 
        
        /// <summary>
        /// 对应淘宝 API: taobao.item.get
        /// </summary>
        public Item ItemGet(ItemGetRequest request) {
            return client.Execute(request, new ObjectXmlParser<Item>(new ParseData(request.GetApiName(), "item")));
        }
      
        /// <summary>
        /// 对应淘宝 API: taobao.items.all.get
        /// </summary>
        public PageList<Item> ItemsAllGet(ItemsAllGetRequest request) {
            return client.Execute(request, new ListXmlParser<Item>(new ParseData(request.GetApiName(), "items", "item")));
        } 
    }
}
